package com.bawei.mall.product.controller;


import javax.servlet.http.HttpServletResponse;

import com.bawei.common.core.utils.poi.ExcelUtil;
import com.bawei.mall.product.domain.MallProductAttribute;
import com.bawei.mall.product.service.IMallProductAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bawei.common.log.annotation.Log;
import com.bawei.common.log.enums.BusinessType;
import com.bawei.common.security.annotation.RequiresPermissions;
import com.bawei.common.core.web.controller.BaseController;
import com.bawei.common.core.web.domain.AjaxResult;
import com.bawei.common.core.web.page.TableDataInfo;

import java.util.List;

/**
 * productController
 *
 * @author bawei
 * @date 2024-07-03
 */
@RestController
@RequestMapping("/attribute")
public class MallProductAttributeController extends BaseController
{
    @Autowired
    private IMallProductAttributeService mallProductAttributeService;

    /**
     * 查询product列表
     */
    @RequiresPermissions("product:attribute:list")
    @GetMapping("/list")
    public TableDataInfo list(MallProductAttribute mallProductAttribute)
    {
        startPage();
        List<MallProductAttribute> list = mallProductAttributeService.selectMallProductAttributeList(mallProductAttribute);
        return getDataTable(list);
    }

    /**
     * 导出product列表
     */
    @RequiresPermissions("product:attribute:export")
    @Log(title = "product", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallProductAttribute mallProductAttribute)
    {
        List<MallProductAttribute> list = mallProductAttributeService.selectMallProductAttributeList(mallProductAttribute);
        ExcelUtil<MallProductAttribute> util = new ExcelUtil<MallProductAttribute>(MallProductAttribute.class);
        util.exportExcel(response, list, "product数据");
    }

    /**
     * 获取product详细信息
     */
    @RequiresPermissions("product:attribute:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallProductAttributeService.selectMallProductAttributeById(id));
    }

    /**
     * 新增product
     */
    @RequiresPermissions("product:attribute:add")
    @Log(title = "product", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallProductAttribute mallProductAttribute)
    {
        return toAjax(mallProductAttributeService.insertMallProductAttribute(mallProductAttribute));
    }

    /**
     * 修改product
     */
    @RequiresPermissions("product:attribute:edit")
    @Log(title = "product", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallProductAttribute mallProductAttribute)
    {
        return toAjax(mallProductAttributeService.updateMallProductAttribute(mallProductAttribute));
    }

    /**
     * 删除product
     */
    @RequiresPermissions("product:attribute:remove")
    @Log(title = "product", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallProductAttributeService.deleteMallProductAttributeByIds(ids));
    }
}
